package com.guigu.pd.base.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.guigu.common.utils.PageVo;
import com.guigu.pd.base.entity.*;
import com.guigu.pd.serviceapi.pojo.TruckLicenseEntity;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.guigu.pd.base.service.TruckDriverService;
import com.guigu.common.utils.PageUtils;
import com.guigu.common.utils.R;



/**
 * 司机表
 *
 * @author deyran
 * @email deyran@gmail.com
 * @date 2022-07-19 19:09:01
 */
@RestController
@RequestMapping("base/truckdriver")
public class TruckDriverController {
    @Autowired
    private TruckDriverService truckDriverService;


    /**
     * 分页查询司机信息
     * @param params
     * @return
     */
    @GetMapping("/querytruckDriverfy")
    public PageVo<TruckDriverEntity> querytruckDriverfy(@RequestParam Map<String, Object> params) {
        TruckDriverEntity truckDriver = JSON.parseObject(JSON.toJSONString(params),
                TruckDriverEntity.class);
        LambdaQueryWrapper<TruckDriverEntity> queryWrapper = new LambdaQueryWrapper<>();

   /*    queryWrapper.like(StringUtils.isNotBlank(truckDriver.getUserId()),
                TruckDriverEntity::getUserId, truckDriver.getUserId());*/

  queryWrapper.like(StringUtils.isNotBlank(truckDriver.getFleetId()),
                TruckDriverEntity::getFleetId, truckDriver.getFleetId());

        Integer page = Integer.valueOf(params.get("page").toString());
        Integer limit = Integer.valueOf(params.get("limit").toString());

        PageVo<TruckDriverEntity> list = truckDriverService.queryTruckDriverfy(page,
                limit,queryWrapper);
        return list;
    }

//    @RequestMapping("/getbyId/{id}")
//    //@RequiresPermissions("base:truckdriver:info")
//    public TruckDriverEntity getdriverbyId(@PathVariable("id") String id){
//        TruckDriverEntity truckDriver = truckDriverService.getdriverbyId(id);
//
//
//
//        return truckDriver;
//    }



    /**
     *
     * @param id
     * @param fleetId
     * @return
     */
    @GetMapping("/updatdriverfleetxxebyid/{id}/{fleetId}")
    public R updatdriverfleetxxebyid(@PathVariable String id,
                                     @PathVariable String fleetId) {

        UpdateWrapper<TruckDriverEntity> updateWrapper = new UpdateWrapper<TruckDriverEntity>();

        updateWrapper.eq("id",id).set("fleet_id",fleetId);

        boolean b = truckDriverService.update(updateWrapper);
        if(b){
            return R.ok("修改成功");
        }
        return R.ok("修改失败");
    }

    @GetMapping("/getcarinfobyid/{id}")
    public R getcarInfobyId(@PathVariable(name = "id") String id) {
        TruckDriverEntity truck = truckDriverService.getcarInfobyId(id);


        return R.ok();
    }



    @GetMapping("/getdfdriver")
    public Integer getdfdriver() {
        List<TruckDriverEntity> list = truckDriverService.list();
        return list.size();
    }

    @GetMapping("/getztdriver")
    public Integer getztdriver() {
        List<TruckDriverEntity> list = truckDriverService.list();
        return list.size();
    }


}
